﻿import com.darronschall.DynamicRegistration
import flash.geom.Point;
/**
 * ...
 * @author wangjun
 */

class ps.imgCtrl.Scale
{
	var lis, per,  onVV;
	private var bb:Boolean;
	private var factor:Number;
	private var vvScope:Array; 
	private var ctrl:MovieClip;
	private var mc:MovieClip;
	private var regPt:Point;
	public function Scale(	mc:MovieClip,   bb:Boolean,	vars:Object	) {
		this.mc = mc;
		this.bb = ( bb == null)?true:bb; 
		this.onVV = (vars.onVV == null)?false:vars.onVV;
		this.factor = (vars.factor == null)?null:vars.factor;
		this.factor = (vars.factor == null)?null:Math.floor(this.factor * 100)*0.01;//取2位小数 
		this.vvScope = (vars.vvScope == null)?null:vars.vvScope;		
		this.regPt =(vars.vvScope == null)?null:vars.regPt;	
		if( this.bb ){
			DynamicRegistration.initialize(this.mc );
			if(regPt==null){
				//_root['mpo'].trace('注册' + this.mc._width * .5)
				//_root['mpo'].trace('注册' + this.mc._height * .5)
				this.regPt = new Point(this.mc._width * .5, this.mc._height * .5);
				this.mc.setRegistration(this.mc._width*.5, this.mc._height*.5);
			}else {
				//_root['mpo'].trace('注册' + this.mc);
				//_root['mpo'].trace('注册' + regPt.x);
				//_root['mpo'].trace('注册' + regPt.y);
				//trace('regPt注册'+regPt.x)
				this.mc.setRegistration(Number(regPt.x), Number(regPt.y));
			}
		}
		
	}
	public function updatePos(prop, oldVal, newVal) {
		//this.rBar.y = (this.p0-newVal)/this._s+this.a0; 
		//_root.tf.text += '\r' + newVal
		if (newVal == oldVal) return;
		var xs:String;
		var ys:String; 
		if (this.bb ) {
			xs = "_xscale2";
			ys = "_yscale2";
		}else { 
			xs = "_xscale";
			ys = "_yscale";			
		} 
		if (this.factor == null) {
				// 最简 
				// newVal * 100
				//trace('state1')
			this.mc[xs] = cvv(this.mc[ys] = newVal * 100); 	
		}else {		 
				// 加比例因子
				// newVal * 100 / factor
				//trace('state2')
			this.mc[xs] = this.mc[ys] = cvv(Math.floor(newVal * 100 / factor*100)*0.01); 
		} 
	}
	public function cvv(vv) {
		if (this.vvScope  != null) {
				//trace('state3')
			return A2.utils.Maths.vvScope([0, 100], this.vvScope, vv)
		}else { 
				//trace('state4')
			return vv;
		}
	}
	public static function set0(mc:MovieClip) {
		mc._x = 0;
		mc._y = 0;
		mc._xscale = 100;
		mc._yscale = 100;
	}
}